﻿


const Peng = {
  Show: function (str, object) {
    let Alertbody = document.querySelector('body');
    let div = document.createElement('div');
    let I = '';

    if (object.Icon != undefined && object.Icon == true) {
      switch (object.type) {
        case "Danger":
          I = `<i class="far fa-times-circle"></i>`;
          break;
        case "Waring":
          I = `<i class="fas fa-exclamation-circle"></i>`;
          break;
        case "Success":
          I = `<i class="far fa-check-circle"></i>`;
          break;
      }
    }

    div.innerHTML = I + str;
    div.className = "Alert";
    div.classList.add(object.type);


    Alertbody.appendChild(div);
    setTimeout(() => {
      div.classList.add("Show");
      setTimeout(() => {
        div.classList.remove("Show");
        setTimeout(() => {
          div.remove();
        }, 300);
      }, 1500);
    }, 5);
  },
  confirm: function (object, btn) {
    let Alertbody = document.querySelector('body');


    let confirmbox = document.createElement('div');
    confirmbox.className = 'confirmbox';

    let confirm = document.createElement('div');
    confirm.className = 'confirm';

    let title = document.createElement('div');
    title.className = 'title';
    title.innerHTML = object.title;


    let p = document.createElement('p');
    p.innerHTML = object.content;

    let button = document.createElement('div');
    button.className = 'btn';


    let ok = document.createElement('button');
    ok.innerHTML = '确定';
    let cancel = document.createElement('button');
    cancel.innerHTML = '取消';


    ok.onclick = () => {
      btn(confirmbox);
    }

    cancel.onclick = () => {
      this.closeconfirm(confirmbox);
    }




    button.appendChild(ok);
    button.appendChild(cancel);



    confirm.appendChild(title);
    confirm.appendChild(p);

    confirm.appendChild(button);








    confirmbox.appendChild(confirm);
    Alertbody.appendChild(confirmbox);






    setTimeout(() => {
      confirmbox.classList.add('active');
      confirm.classList.add('active');
    }, 50);


  },
  closeconfirm: function (Element) {
    let confirm = Element.querySelector('.confirm');

    confirm.classList.remove('active');

    Element.classList.remove('active');

    setTimeout(() => {
      Element.remove();
    }, 200)

  },

  load: function (obj) {
    let Loging = document.createElement("div");
    Loging.className = "Loging";

    let LogingBox = document.createElement("div");
    LogingBox.className = "LogingBox";

    if (obj.box != undefined) {
      LogingBox.classList.add(obj.box);
    } else {
      LogingBox.classList.add("Rows");

    }

    let loader = document.createElement("div");
    loader.className = "loader";


    if (obj.style != undefined) {
      switch (obj.style) {
        case "circle":
          let img = document.createElement("img");
          if (obj.color != undefined) {
              img.src = `/HelpContent/Tips/img/${obj.color}.png`;
            
          }else{
              img.src = `/HelpContent/Tips/img/purple.png`;
          }
          loader.appendChild(img);
          break;
        case "default":
          loader.classList.add("default");
          break;
      }
    } else {
      loader.classList.add("default");
    }

    if (obj.color != undefined) {
      switch (obj.color) {
        case "blue":
          document.documentElement.style.setProperty('--StyleColor', "#449CFF");
          break;
        case "ZhutiSe":
              document.documentElement.style.setProperty('--StyleColor', "#F36667");
          break;
      }
    } else {
        document.documentElement.style.setProperty('--StyleColor', "#F36667");
    }


    let Test = document.createElement("div");
    Test.className = "Test";

    for (let i = 0; i < obj.content.length; i++) {
      let span = `<span style="animation-delay:${(i+1)*50}ms;">${obj.content[i]}</span>`;
      Test.innerHTML+=span;
    }





    LogingBox.appendChild(loader);
    LogingBox.appendChild(Test);
    Loging.appendChild(LogingBox);



    let Alertbody = document.querySelector('body');
    Alertbody.appendChild(Loging);
    setTimeout(() => {
      Loging.classList.add("active");
      LogingBox.classList.add("active");
    }, 0);

    if (obj.time != undefined) {
      setTimeout(() => {
        LogingBox.classList.remove("active");
        setTimeout(() => {
          Loging.classList.remove("active");
          Loging.remove();
        }, 150);
      }, obj.time);
    }

    return Loging;
  },
  closeload: function (Element) {
    let LogingBox = Element.querySelector(".LogingBox");
    LogingBox.classList.remove("active");
    setTimeout(() => {
      Element.classList.remove("active");
      Element.remove();
    }, 150);
  }

};


